package week1.blog_code.exer1002;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;

public class Main {
    private static int[] numArr = new int[51];
    private static StringBuilder stringBuilder = new StringBuilder();
    public static void main(String[] args) throws IOException {
        // 缓冲输入流（高级版平替scanner）
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        // 打印流（高级版平替System.out.print）
        PrintStream printStream = new PrintStream(System.out);
        String line = null;
        while ((line = reader.readLine()) != null) {
            int target = Integer.parseInt(line);
            numArr = new int[51];
            stringBuilder = new StringBuilder();
            dfs(numArr, 0, 0, target, target);
            printStream.print(stringBuilder.toString());
        }

    }

    /**
     * @param numArr 当前拆分元素构成的数组
     * @param curLen 当前拆分数组长度
     * @param curSum 当前拆分方法之和
     * @param target 目标和
     * @param curNum 当前遍历到的数
     */
    public static void dfs(int[] numArr, int curLen, int curSum, int target, int curNum) {
        // 出口：当前拆分和==目标和就不用继续搜索
        if (curSum == target) {
            for (int i = 0; i < curLen - 1; i++) {
                stringBuilder.append(numArr[i] + " ");
            }
            stringBuilder.append(numArr[curLen - 1] + "\n");
            return;
        }
        for (int i = curNum; i >= 1; i--) {
            if (curSum + i <= target) {
                // 将i值加入拆分数组中
                numArr[curLen] = i;
                // 继续深搜
                dfs(numArr,curLen + 1, curSum + i, target, i);
            }
        }
    }
}
